package com.xuzimian.springboot.scaffolding.router;

import com.xuzimian.springboot.scaffolding.httphandler.HomeHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@Configuration
public class Routes {
    private HomeHandler homeHandler;

    public Routes(HomeHandler homeHandler) {
        this.homeHandler = homeHandler;
    }

    @Bean
    public RouterFunction<?> routerFunction() {
        return route(GET("/api/").and(accept(MediaType.APPLICATION_JSON)), homeHandler::getSpeaker);
    }
}